/*
kunpengsecl licensed under the Mulan PSL v2.
You can use this software according to the terms and conditions of
the Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at:
    http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

// a simulation of qcalib

#include "teeqca.h"
#include "testdata.h"
#include <string.h>
#include <cjson/cJSON.h>


#define NODAAREP "{\
        \"report_sign\":  {\
                \"sce_as_no_daa\":        \"jsXI4_rBHPY-9zbNqVVwnn1W1-n5lRxG37hwSpqNCPgbPnVE87sKfeB9sD-VA1nJct8BpkUVg3PsZ1EhqVGnmiRGevsTDacimzan_HKuUrA8L69JsT7EQauObFQFJvsZWnbg6ixB-KiAXvHbJrbsPok-s-3M-wg9fmFMcRfRfoUtuI2LLRofDgYB0wfNWdc7xhWr9u6h8dzjbq4Lof2jsbVB2vZLu7tWkixWXsGHPhjT31ejGXcGT8cI6HMXvnbWfHOrMTCAQ3tcd6-JTKtjgmcFSMb_DrXpjdvgNE0j8LwMpOa2bErsZzLfYspOyvdjatQr5s4ZwW2533Q3gq296Phy-MYMh3ByW9HDBJY5UGAszQ0eVWN0tGBbvTxHBGljL1p_9x4t2pNnZT1T6c393B8bg-XdA3Q1cz60cQzYG6JxCf2OdCfRtSbBvO8c0KAoO8zHFCbZpsyOaRtcZ-UaUI3uMMcMV0ooZVt54aToMeztP1L7PgMVfY0evacr_ECOWo_vN3Deh1PwRQmAHhMDeCOhcAXy7SsSTbT1RM5JTcOsaHFvTizdhqfzDMndUa5kBuRZZKbxDk6d5lWG1yExJoJ-qOobtVrIGXh9QrzqNCH6v16W7K37QmuAV1TKfHfrsTvkys8smSd--njeZUy4rS-s0q-ATwEKbsk_BTxBDok\"\
        },\
        \"akcert\":       {\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kQjZhTGlhX0FVNXRYem1JeV9FRWdZaTJzX01UeldGejVpSU9VSEpWLXhOT3VSNnZFSE1Kc05UZDVKNlZRZWU2cTZVNjFmVENOV0tCY3duaWVVZWRrMjh5MnRLclJ3aWY0eVU0SWVaM0k3UV9BM2lhUzhwclc1U3M0ekk1S1phWllIclJBQzJaUXRaNl9SZGozYkR3MjAtVzhtVGloaXVza3FOLXgzUkFGVkczYnA2R2Y3LWlEMUxWU2o1bnFRN1k5eVdIbmhOYWJGZGxRMEkwRHlESzV4WkVnNkRCUHlYS21KOWVkSXlEalZMSlN1MCIsCgkJCSJlIjoJIkFRQUIiCgkJfQoJfSwKCSJoYW5kbGVyIjoJInByb3Zpc2lvbmluZy1vdXRwdXQiCn0\"\
        },\
        \"payload\":      {\
                \"version\":      \"TEE.RA.1.0\",\
                \"timestamp\":    \"9223372036854775800\",\
                \"nonce\":        \"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5_gA\",\
                \"scenario\":     \"sce_as_no_daa\",\
                \"uuid\": \"e08f7eca-e875-440e-9ab0-5f381136c600\",\
                \"hash_alg\":     \"HS256\",\
                \"sign_alg\":     \"PS256\",\
                \"ta_mem\":       \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                \"ta_img\":       \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                \"ta_attr\":      \"\",\
                \"tcb\":  \"\"\
        },\
        \"handler\":      \"report-output\"\
}"

char nodaaprovision[] = 
"{\
        \"signature\":    {\
                \"drk_cert\":     \"TUlJRWtqQ0NBM3FnQXdJQkFnSVJFVk9HdExqeldMKzk2WEpGeWlYSVEwOHdEUVlKS29aSWh2Y05BUUVMQlFBd1BURUxNQWtHQTFVRUJoTUNRMDR4RHpBTkJnTlZCQW9UQmtoMVlYZGxhVEVkTUJzR0ExVUVBeE1VU0hWaGQyVnB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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\
                \"drk_sign\":     \"0HbdRwbUdPKtIFH8tCNioT50pDhT4TFwi7HPCZEdyBaFBEjK9HIRNiiX9x4QXTMdgW7-jo2-Z0fvzd9a9mgOzdXBSkT-8277Hvzq_yxMsVUlsrRU2oXpMWJFXDdlYu8piMftr6VGRg8M0Vy5Tr0O0PP7CpRujklkGgDkqNScpNO7taI8Yn44saEvGhR3P0MluC9MsvVQRQiMk1mmbgyxFpYo-NHBNam5G67Az55CqmdmSGE88qQAhBnRc5bp4pubpVlsA0Or7SG6QMHHq0Tx9pbXjlgcVtNDz7cmXSX7ITZ3p8kcq5vy3RLV3JdXN454e356KmOjhZlCeoRw_fHl1h2lfroUWqQbDpB_FBp5hsNCtqNa94x-J8OM-VvryKrmp-anwqx4RJ3b4FVwtTRU_2EIfgPeidU1Uh2sbdTKkhLw8msf215NfcgcN9J-nPhQtjsUhfjUiYDpbDILqiBabn_VIf0MckyZXdQSD6TKvctOY7SesMUhRx24f3LFOSmIH1yLlu7celsKr5zfDvO4lH4g_HdxlYzJRdM33EE13xkXohGCrpLyjJ4hbP7nrmwKpGJNdM6GcHQj55UowUkCkuFlZfZJz8r3iPUwcg1Gb8SqLqvP1MLAxO7O4JwccdiR8uNo-iEug796_AmOsvqRhiH9oF7V1xa3H84ry0RH-ME\"\
        },\
        \"payload\":      {\
                \"version\":      \"TEE.RA.1.0\",\
                \"timestamp\":    \"9223372036854770000\",\
                \"scenario\":     \"sce_as_no_daa\",\
                \"sign_alg\":     \"PS256\",\
                \"hash_alg\":     \"HS256\",\
                \"qta_img\":      \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                \"qta_mem\":      \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                \"tcb\":  \"\",\
                \"ak_pub\":       {\
                        \"kty\":  \"RSA\",\
                        \"n\":    \"v88TJ5_JSal574ODMTl2S1T2HMxZtcGcvFJa2CYQ3w7Q8otCZU4tKfXZBXQH4iZGeaBCoNFB1vinzMw5X1hFiPXMHfW-6wc1N-f1DC4Bu-WMhckdcz0qK3_Ptr9EasTs3LB5nUMffBVivm0EzW1LFIOyirY6g3NmKdjJechw9CV7XtosYT50-cgzJCwU1I7l3_qOTHq4nQ4htuuzQUXOh7nTRfFYbYRVLqF9YSFGyb5FL4Zay-2XLWRjqyX93TDN2zNaVcQa2jREAzne5Vx4zomSNe2Fjibke8ykYyvgu3ERsbhK71GAvOLt_Xrx9VpNi_oTjoEofjbh1dD9uFwO8DCk2pJm8SKlVE3b_HV9wLRNQDW13OoCMr5SDxkVIPgMCgXbpdaJRjL41d7dSX3lE45Zy6Tg7TyyAQnhbYwWz87NCnXp0OLjcejEj6xJI391Pids5yTldFfN3b_OgUKEbbNhwbIFtOfW93B15jKTnqaYMCbtsWiQxiJSZuyY6TuIeassbiLUIryzShGw6_kisnecYmzHJdQ7yAU9ZA38QAto1AyvADmfIPeaFVmqp_Z6x8aMLNndowoiwUw2UjgZdGyCDMR_A46OdsuvIec5Uiob5hfa7JIU0jhkez1fAUd8IK4AJ3s6Qd2WqQoO2891eCAvdgXG9XIwJA5cHI0YW30\",\
                        \"e\":    \"AQAB\"\
                }\
        },\
        \"handler\":      \"provisioning-output\"\
}";

char daaprovision[] = 
"{\
        \"signature\":    {\
                \"drk_cert\":     \"TUlJRWtqQ0NBM3FnQXdJQkFnSVJFVk9HdExqeldMKzk2WEpGeWlYSVEwOHdEUVlKS29aSWh2Y05BUUVMQlFBd1BURUxNQWtHQTFVRUJoTUNRMDR4RHpBTkJnTlZCQW9UQmtoMVlYZGxhVEVkTUJzR0ExVUVBeE1VU0hWaGQyVnBJRWxVSUZCeWIyUjFZM1FnUTBFd0hoY05Nakl3TkRFeE1EWXpOVEF5V2hjTk16Y3dOREEz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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\
                \"drk_sign\":     \"JHaNmOryJBMjKZvMzn3fjevD-DBTpfejTxktYo9yPKry4JmVjjaRJL3f8hRGUaY49hRwukL4oWuqHnfD4pnbtvUzlqrmJmm3v6j8BtOMik0cOnL_54UGjq7G2z8J-Fe-nREuDfa5FKpBBN-Vt9LpRfbHFJdGTJlPkdvwVSUmWUC97pDN4rBM-ZQAU1poyycHHCGbLM8SxoWA-BzQHwIrowBjLtNPJ-EWHFoVK2VrYI1yX1wK_6_CB0f-4w7y2Lv2c8oxyS52Up2w69E7eMlWUn21VvBw4hInFto0H6uT-PC5sTxjOctLvIUT5VCuHQx4LGLRT90j4I2C23mQmEMZI1YPxBGx5gNUI8zv5aZBnRVLME_UoBFp3j3aM1Varkc1eh1i-Bs3eT2TRw3MUYjPYiLwYo_O5sGdCA23OPEqo1Kl53gGYIMZa5uS4udNJeAtdQrQerldz0Yt8Fo5oInz-zBmiQAY9T3SGIQr112qRL9QK-Msfn0onS2RTymxzk2ALBXUbX8hFrWmY07aBea-HbbOFfs0W0DXuJN2um_RTWUOUf7tDbDjNIlaiOidUf8Li0AMlWAu-Sgqr1ackfnq0MwQOoSd6BXqaFnH9RSQGjy3d8E_hD7BFkHr-3diqJ9x-Ie-pvIFcedv4C-jqlJhAuse0jB1nigkIae8u3xL18U\"\
        },\
        \"payload\":      {\
                \"version\":      \"TEE.RA.1.0\",\
                \"timestamp\":    \"9223372036854770000\",\
                \"scenario\":     \"sce_as_with_daa\",\
                \"sign_alg\":     \"PS256\",\
                \"hash_alg\":     \"HS256\",\
                \"qta_img\":      \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                \"qta_mem\":      \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                \"tcb\":  \"\",\
                \"ak_pub\":       {\
                        \"kty\":  \"DAA\",\
                        \"qs\":   \"QAAAAP9tjoY4PBDyD0jYoox0nJ3Xhura3xVPu7Xy3hGLRC30RzQF1oZsXoKzGec9Hiad46dEZh2JAvewQ5LGHaipiHlAAAAA4YVQ_aQLNwEbzrQc-EqaNAHT8lfLq7vTJfTfHAAyDgzZCRpxbYK0DZ-ZmFHjwNiFtVIZwjtUAacSx_LQwPxEyA\"\
                }\
        },\
        \"handler\":      \"provisioning-output\"\
}";

struct ra_buffer_data_s test_provision_array[] = {
    {// case1: report-no as
        0, NULL},
    {// case2: report-as no daa
        //sizeof(nodaaprovision), nodaaprovision},
        sizeof(nodaaprovision), nodaaprovision},
    {// case3: report-as with daa, without bsn
        sizeof(daaprovision), daaprovision},
};

char noasreport[] = 
"{  \
        \"report_sign\":  { \
                \"sce_no_as\":    \"RIipRRfPKYILcAVDNr5F0Y13Y4tV2XH9MJD54VkAweVLeVLfUmkhAzVCN65yAts6pk51_nQiSZWcwMFePEMC5e93Mgkvls1f1pqnkDa6UcXUO-7Mm3gm1sDXr1lp5pClUQ_xGleOlHxRl7KiPwVCNm5dShgF2zrXk_F4dhrf06o4GU12HwTMhvs7m2CCp2VF76CBoJaveiZDUpZA6tHebtvqIWEUtqEyIuAVtOGee7bSoGJC54CtZmy_YzkB3W3RaWtPMus2vVdV1JZgEcdni_VVw1mBkicON9O2g1Vk2S8y75wql3q7-MgHyR13Pc9hgvXZYg8Lts3yo0CdvD9NPsKgA2LoB_rRHjd3PLe87mXYNhOErHnZotTTmD3GKOiU0fPnfyXCqGXOCS6by3hpiY9QclSP8inYUjGtxElTyzDJaXM-y1iExxvMdj1zQPkcSpk32ZAakDEH2fOEiCmU0cYTcdJTzEoBTw8hGoNb0FOFUMc-YVQCx9VzMjYF_-wD0xmyLzmVrWuwytQ6Dg8tIacILlt27bV8PZnLoyS0vOMIGjJ7A-NpmJSJRL5WGs7Hx-5WTVOR9Xg3p6z7jJypB61FMdkvpgltw89eYt7TVjyyrCovpJUg-zKg2YbET2_-GyjHoCLNutuVvGqPNEH9I4Kh9MZEKzZiiKKutJUhF_E\"\
        },\
        \"akcert\":       { \
                \"sce_no_as\":    { \
                        \"signature\":    { \
                                \"drk_cert\":     \"TUlJRWtqQ0NBM3FnQXdJQkFnSVJFVk9HdExqeldMKzk2WEpGeWlYSVEwOHdEUVlKS29aSWh2Y05BUUVMQlFBd1BURUxNQWtHQTFVRUJoTUNRMDR4RHpBTkJnTlZCQW9UQmtoMVlYZGxhVEVkTUJzR0ExVUVBeE1VU0hWaGQyVnBJRWxVSUZCeWIyUjFZM1FnUTBFd0hoY05Nakl3TkRFeE1EWXpOVEF5V2hjTk16Y3dOREEzTURZek5UQXlXakE2TVFzd0NRWURWUVFHRXdKRFRqRVBNQTBHQTFVRUNoTUdTSFZoZDJWcE1Sb3dHQVlEVlFRREV4RXdNalpRVUZZeE1FdERNREEwTVRjNVZEQ0NBaUl3RFFZSktvWklodmNOQVFFQkJRQURnZ0lQQURDQ0Fnb0NnZ0lCQU5uOGJ6SXJneGFBNFh6RkZYSzhZYUhOVU5IZ2hoRzJZeEg4Znc4a0lTL1BaY3NkZXo2WTVLZ3BNVDJ0ZTRkVkpYa2FDeFVld1IxZm1Vb1AwZStsaWtYeVlaZm1xeDF6SVZoazRtM2tuK0lYN3g5c3RMeitvR0NaYXg2MXMrdURhNnBITGN4VDVKWUZZaFVHZ2FlbE1wS2lxamEvSFo2aHRCUW1oZ1YvNFFxTHl0ellKSlc2ZVFoRnMrQW9URUx5RmFBa0JXUlkzaVFRbE55NmhsV2xGa0xUQkdYSWYvZ0E2MmgyeE5wd3BPVkdjRi9mL2ZrdTBlR3JVZHVZUG04YVRlNnNITzZIOVdhY0xwU28wd1Nqc2hoME8xUzdrcWVJUTFLdWhDY0lkQnJKRWNyalA5RFUzQnJweGxzck5JKytHeTV0ays5Q3RZTzVsTktVbTJHUVpDUlZKaDFxUWNXb3hQWTZUYkNJZTZiMi9oaFJGdHVJM2VYcGczLzlmWW1NYllKb3ZTb1dxekErUzZCL092dmdCVjFhNzNod2kvQldiWjg5bWM3W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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\",\
                                \"drk_sign\":     \"j6YnW9t0RbxYkGt_KQoHdvHoeTHm40V6UWkaazcOY1igfi9XjBB_OGDHMx0uWJijhHGbpOx93sNgVc3yQJBLiQwxkLMeYIc6qaTZBaiiq9kxj-FGI952bbv65WF_JfPeCXvrgl0Hlhen1fhVV22PMmoK_MJ6vB9Pw5bsbTvCFpwlFA963X0_XWNLAzETp5rbjdkZd7dOmBmYFjm6DfrfO86xNeVrWYEomhpVYChEYkXSWkAeS7OCBSQHFJaw5HnKRtPGQDIe8C8cnPX8cI2RF-KVmBODxRz8mRQYosrrHMj8RqO0KG2JgPwmXZvLNahWDh_GyLBStHHNh7oDYmfX_DFEfqZlSrSUJCkmtQnO6-COW8KM85l1EYz9SFzwcdjh-qgG6p80NyfULDBTIUTNY6rFKTCGqD19BSd8HlOaaoSdw3nXlR4xSpMO3TxojLCkSOup8QtLO6bgUN5vJBEXuo6U33FcQXn-4-wL9SPuAOsa1PV7sSGk17nT31bT7LfqNzM4OO8eYnrPG98xM_Te6nkVJSfUc1e7mRelNUtZpwIxRRIhnDn37pAcqpCESiANxSko8-353ty8cm4VChUsRomR7AtFgRBuPqRrHx2J3eiRE5FsIiXBaMdEXbXHE70wexgEtw0RwhtgHv87iMgLo5H_D9KGWTByzNbjtC04W9g\"\
                        },\
                        \"payload\":      {\
                                \"version\":      \"TEE.RA.1.0\",\
                                \"timestamp\":    \"9223372036854770000\",\
                                \"scenario\":     \"sce_no_as\",\
                                \"sign_alg\":     \"PS256\",\
                                \"hash_alg\":     \"HS256\",\
                                \"qta_img\":      \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                                \"qta_mem\":      \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                                \"tcb\":  \"\",\
                                \"ak_pub\":       {\
                                        \"kty\":  \"RSA\",\
                                        \"n\":    \"yf1gDkBMbaI7Z9t6A2WPBjRB3PfYaSPV0_hxu44bx53_Qt1pyvH4Y-S_34HJN5lIcdAxk-iuaTclK6VqZ919chgmlwf46peN0TCI0l4ijtgfpHn-naeeeVztyXBIc_xRJKLG24XPaszZoG9StlfpJOB8-WvAqw-c6wtc1I9BLkooGUYfJ-eddpD1-22DtfcgIKxOwp3eM0N5FQoN5bYAHIT68ZLE2ZsfhTuEfnm6uZDoETk-H21BiSICwReqmXyGrWC6-ISE4W5hz1vEZnz7u66a5CXt0Xaz6WiJ3dOYAa-a4rXDO4lGTttZ6wWu6QHANQC5HxrO0ySr8p5G2RK5tsrEG8yZMExo66bfJ9y2JhT4QQ8Xsh1CVGA6mZzxK4Ir56cjv8_ZHhYQNzOi4Y6KSm_4unR1p5USD_KFKQpXTrb_4fo3oJ8h_hWnGunc7FVUNuQGNbCqeuwsWfptyqQDH6CjqW1Z6mMR64rYaoOOxZohSdmmZH5xbW2h_5wkhkQK3Rv15oHuJX8j5Yz8NED6bXTOU1t28E4c1HAPRAEGNF3PxCWWiBiwWAfGHhbRvZIZ3pFVNHciag_E8e90tXQIP0aiYEn22esDTY4CpaMDEzsrkLd351QSEbW7uJACQBBH8PZvhNCLMIkGayh82NOu4cNjErG95BcElYHX0H40MoE\",\
                                        \"e\":    \"AQAB\"\
                                }\
                        },\
                        \"handler\":      \"provisioning-output\"\
                }\
        },\
        \"payload\":      {\
                \"version\":      \"TEE.RA.1.0\",\
                \"timestamp\":    \"9223372036854775800\",\
                \"nonce\":        \"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5_gA\",\
                \"scenario\":     \"sce_no_as\",\
                \"uuid\": \"e08f7eca-e875-440e-9ab0-5f381136c600\",\
                \"hash_alg\":     \"HS256\",\
                \"sign_alg\":     \"PS256\",\
                \"ta_mem\":       \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                \"ta_img\":       \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                \"ta_attr\":      \"\",\
                \"tcb\":  \"\"\
        },\
        \"handler\":      \"report-output\"\
}";

char nodaareport[] = NODAAREP;

char daareport[] = 
"{\
        \"report_sign\":  {\
                \"sce_as_with_daa\":      {\
                        \"sign.bsn\":     \"\",\
                        \"sign.j\":       \"\",\
                        \"sign.k\":       \"\",\
                        \"sign.h2\":      \"D9bUlAMZPiZwyHXW62ghOxa0NejLWV_MDL1-10RAQoppvqshKNUWIVMpcw9tw5iFYI9ndKNhQMHuNeIF5KXP5A\",\
                        \"sign.s\":       \"p4dWeEJX_gIbzcqW3FVd0rQE-Dp7UN8a80e4mxgRP9-aRBmYm8K34BR61QN9TRgiak4WmGO4vwF_EuwYRJrV1w\",\
                        \"sign.nm\":      \"IToTSn8v3KO506yCIkVDLCLfFaAN6vPYd-J6YgsSX6np4hbJKdBEg3mrjErajy9PQFjjM3fV1tJR46EfZiqGfw\"\
                }\
        },\
        \"akcert\":       {\
                \"sce_as_with_daa\":      \"iAAAAEAAAAA3ftdgt-rg7pFesSuuy-1eSVyPBUkKlP-gD1szPkm1hlHFp8YDR0LowUdC8Gwvvojh_f7MBqrZsT4MKJrwXWpJQAAAAH9SKhUEbAYm-Vf73jyct4fWib_PAfh6BXjcO2H6i_Laf_KOmV4MnxRDJ1I7SL-NjFjTZff-CCBCNMaLflzJM_eIAAAAQAAAAPe1j51qlPfPdi_b28HVbf1hWnuhrzgqpdJf8wkluoVg3Rwatb5JIAZR9dzkNk3QwecukuR_H7jPtNzvASOf5K1AAAAAx4nq6rvrGPKmgq-Joia5E3ROole3U5Dt42nOw61h-8QRM6P2-ASs01R87KZb50gdGSytILfxUXvcv8SGd6CItogAAABAAAAA-DCfI0Z0d1K7Y5vwLzx2wFPCI3op9n_eVYMQfGWiF6R5ZC6MoRWvEksOqfKo_8tec5ZUV-XIWRWYvHLQUCrU4EAAAACQ613rlxjFv3Q03uxssD_lw7iJeh_NQmp-1KmSR34ZlI-46uXZRuLkSl2eMkv91hXf_BKwYjcEuMVXRLF6-jHiiAAAAEAAAAD3d_dEF2nQke5jzNRLIXsuG8v8v9yMPpzUH6OwOqT6tQb5EveJzZzgEKYjozQq3s2XXT76xGTpmrre9Uaub__xQAAAAHqO2XIAl-8s9NMEvn3LKpDdO_yLHlb7N6hh-Fj-MjO71etAGFeybK0grC1_4PCgwgJG9uVuMkN5GtSVszZqFdc\"\
        },\
        \"payload\":      {\
                \"version\":      \"TEE.RA.1.0\",\
                \"timestamp\":    \"9223372036854775800\",\
                \"nonce\":        \"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX5_gA\",\
                \"scenario\":     \"sce_as_with_daa\",\
                \"uuid\": \"e08f7eca-e875-440e-9ab0-5f381136c600\",\
                \"hash_alg\":     \"HS256\",\
                \"sign_alg\":     \"PS256\",\
                \"ta_mem\":       \"KlYpkZzjREFXd0GwwgLas3gJ60HB0DQfsn8sHlZ7SjE\",\
                \"ta_img\":       \"FaOPRQvji8yNYvo1K8XDMDXXK2lkwiegprur8djeKgc\",\
                \"ta_attr\":      \"\",\
                \"tcb\":  \"\"\
        },\
        \"handler\":      \"report-output\"\
}";

struct ra_buffer_data test_report_array[] = {
    {// case1: report-no as
        sizeof(noasreport), (uint8_t *)noasreport},
    {// case2: report-as no daa
        sizeof(nodaareport), (uint8_t *)nodaareport},
    {// case3: report-as with daa, without bsn
        sizeof(daareport), (uint8_t *)daareport},
};

static int g_scenario = RA_SCENARIO_NO_AS; // default noas mode

static char newreport[20000] = NODAAREP;

bool set_secnario(char *s) {
    if (strcmp(s, "sce_no_as") == 0) {
        g_scenario = RA_SCENARIO_NO_AS;
    } else if (strcmp(s, "sce_as_no_daa") == 0) {
        g_scenario = RA_SCENARIO_AS_NO_DAA;
    } else if (strcmp(s, "sce_as_with_daa") == 0) {
        g_scenario = RA_SCENARIO_AS_WITH_DAA;
    } else {
        printf("set scenario failed, invalid scenario.\n");
        return false;
    }
    return true;
}

TEEC_Result RemoteAttest(struct ra_buffer_data *params, struct ra_buffer_data *out_data)
{
    if (params == NULL || out_data == NULL) {
        printf("invoke RemoteAttest failed, invalid in parameters.\n");
        return 0xFFFF0006; // bad parameters
    }
    if (params->buf == NULL || params->size == 0) {
        printf("invoke RemoteAttest failed, invalid in parameters.\n");
        return 0xFFFF0006;
    }
    cJSON *cj = cJSON_ParseWithLength(params->buf, params->size);
    if (cj == NULL) {
        printf("invoke RemoteAttest failed, cjson parse error.\n");
        return 0xFFFF0006;
    }
    cJSON *h = cJSON_GetObjectItemCaseSensitive(cj, "handler");
    cJSON *pl = cJSON_GetObjectItemCaseSensitive(cj, "payload");
    if (h == NULL || pl == NULL) {
        printf("invoke RemoteAttest failed, cjson get parameters error.\n");
        return 0xFFFF0006;
    }

    if (strcmp(h->valuestring, "provisioning-input") == 0) {
        cJSON *s = cJSON_GetObjectItemCaseSensitive(pl, "scenario");
        if (strcmp(s->valuestring, "sce_no_as") == 0) {
            out_data->buf = NULL;
            out_data->size = 0;
            printf("invoke RemoteAttest succeeded, provision successfully! scenario:%d\n", g_scenario);
            return 0;
        } else if (strcmp(s->valuestring, "sce_as_no_daa") == 0) {
            bool rt = set_secnario(s->valuestring);
            if (!rt) {
                printf("invoke RemoteAttest failed, set scenario error.\n");
                return 0xFFFF0006;
            }
        } else if (strcmp(s->valuestring, "sce_as_with_daa") == 0) {
            bool rt = set_secnario(s->valuestring);
            if (!rt) {
                printf("invoke RemoteAttest failed, set scenario error.\n");
                return 0xFFFF0006;
            }
        } else {
            printf("invoke RemoteAttest failed, invalid scenario.\n");
            return 0xFFFF0006;
        }
        out_data->size = strlen(test_provision_array[g_scenario].buf);
        memcpy(out_data->buf, test_provision_array[g_scenario].buf, out_data->size);
        printf("invoke RemoteAttest succeeded, provision successfully! scenario:%d\n", g_scenario);
        return 0;

    } else if (strcmp(h->valuestring, "report-input") == 0) {
        if (g_scenario == 1) {
            out_data->size = sizeof(newreport);
            memcpy(out_data->buf, newreport, out_data->size);
            printf("invoke RemoteAttest succeeded, get report successfully! scenario:%d\n", g_scenario);
            return 0;
        }
        
        out_data->size = test_report_array[g_scenario].size;
        memcpy(out_data->buf, test_report_array[g_scenario].buf, out_data->size);
        printf("invoke RemoteAttest succeeded, get report successfully! scenario:%d\n", g_scenario);
        return 0;

    } else if (strcmp(h->valuestring, "saveakcert-input") == 0) {
        out_data->buf = NULL;
        out_data->size = 0;
        
        if (g_scenario == 1) {
            cJSON *ac = cJSON_GetObjectItemCaseSensitive(pl, "akcert");
            cJSON *root = cJSON_ParseWithLength(nodaareport, strlen(nodaareport));
	        cJSON_ReplaceItemInObject(root, "akcert", ac);
            uint8_t *tmp = cJSON_Print(root);
            memcpy(newreport, tmp, strlen(tmp));
	        cJSON_Delete(root);
            cJSON_free(tmp);
        }
        printf("invoke RemoteAttest succeeded, save AK Cert successfully! scenario:%d\n", g_scenario);
        return 0;

    } else {
        printf("invoke RemoteAttest failed, invalid handler.\n");
        return 0xFFFF0006;
    }

    cJSON_Delete(cj);
    return 0;
}
